/*
 * Copyright 2010 Christoph Widulle (christoph.widulle@googlemail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */



package com.android1.amarena2d.engine.collision;

import com.android1.amarena2d.commons.Size;
import com.badlogic.gdx.math.Vector2;

public class AABoxCollisionVolume implements CollisionVolume {

    protected final Vector2 boxXY = new Vector2();
    protected final Size boxSize = new Size();

    public AABoxCollisionVolume(float offsetX, float offsetY, float width, float height) {
        boxXY.set(offsetX, offsetY);
        boxSize.set(width, height);
    }

    public float getMaxX() {
        return boxXY.x + boxSize.width;
    }

    public float getMinX() {
        return boxXY.x;
    }

    public float getMaxY() {
        return boxXY.y + boxSize.height;
    }

    public float getMinY() {
        return boxXY.y;
    }

    public Vector2 getBoxXY() {
        return boxXY;
    }

    public Size getBoxSize() {
        return boxSize;
    }

    public AABoxCollisionVolume setBoxSize(final float width, final float height) {
        boxSize.set(width, height);
        return this;
    }

    public AABoxCollisionVolume setBoxXY(final float x, final float y) {
        boxXY.set(x, y);
        return this;
    }

    @Override
    public int getShapeType() {
        return CollisionVolume.ShapeType.AABox;
    }

    @Override
    public boolean intersects(final CollisionVolume other) {

        final float left = getMinX();
        final float right = getMaxX();
        final float bottom = getMinY();
        final float top = getMaxY();

        final float otherLeft = other.getMinX();
        final float otherRight = other.getMaxX();
        final float otherBottom = other.getMinY();
        final float otherTop = other.getMaxY();

        return CollisionChecker.checkAABoxIntersect(left, right, top, bottom, otherLeft, otherRight, otherTop, otherBottom)
                || CollisionChecker.checkAABoxIntersect(otherLeft, otherRight, otherTop, otherBottom, left, right, top, bottom);
    }


}